
/*
===============================================
IComponent
===============================================
*/
namespace Domain.Interface 
{
	using System;
	using System.Collections.Generic;
	using System.Linq;
	using System.Text;
	using Domain.Model;

	public interface IResourceComponent 
	{ 
		/// <summary>
        /// Add
        /// </summary>
		void AddResource(Resource entity);
		
		/// <summary>
        /// Delete
        /// </summary>
		void DeleteResource(Resource entity);
		
		/// <summary>
        /// Get
        /// </summary>
		IEnumerable< Resource > GetResources();
	}
}

/*
===============================================
Component
===============================================
*/
namespace Domain 
{
	using System;
	using System.Collections.Generic;
	using System.Linq;
	using System.Text;
	using Domain.Interface;
	using Domain.Model;

	public class ResourceComponent : BaseComponent, IResourceComponent
	{
		/// <summary>
        /// Add
        /// </summary>
		public void AddResource(Resource entity)
		{
		    Context.Resources.Add(entity);
            Context.SaveChanges();
		}
		
		/// <summary>
        /// Delete
        /// </summary>
		public void DeleteResource(Resource entity)
		{
		
		}
		
		/// <summary>
        /// Get
        /// </summary>
		public IEnumerable< Resource > GetResources()
		{
			return Context.Resources.ToList();
		}
	}
}

/*
===============================================
ViewModel
===============================================
*/
namespace MvcApplication1.ViewsModel 
{
	using System;
	using System.Collections.Generic;
	using System.Linq;
	using System.Web;
	using Domain.Interface;
	using Domain.Model;
	using StructureMap;
	using StructureMap.Attributes;

	public class ResourceViewModel : BaseViewModel
	{
		#region properties
		
		public IResourceComponent ResourceComponent { get; set; }
		
		#endregion
	
		#region ctor
		
		/// <summary>
        /// Ctor
        /// </summary>
		public ResourceViewModel()
		{
			ResourceComponent = ObjectFactory.GetInstance< IResourceComponent >();
		}
		
		#endregion
		
		#region component calls
		
		/// <summary>
        /// Add
        /// </summary>
		public void AddResource(Resource entity)
		{
		    ResourceComponent.AddResource(entity);
		}
		
	    /// <summary>
        /// Delete
        /// </summary>
		public void DeleteResource(Resource entity)
		{
			ResourceComponent.DeleteResource(entity);
		}
		
		/// <summary>
        /// Get
        /// </summary>
		public IEnumerable< Resource > GetResources()
		{
			return ResourceComponent.GetResources();
		}
		
		#endregion
	}
}

